package test1.Demo2;

import java.sql.SQLOutput;

/**
 * ClassName Student
 * Description TODO
 * Author Yanyan
 * Date 2025/11/8 19:39
 * Version 1.0
 */
public class Student {

    private String name;
    private int age = 100;
    //age = 200;

    //静态成员变量，使用类调用，所有实例通用
    public static String classRoom = "B2504";
    //classRoom = 123;

    {
        age = 9;
        System.out.println("实例代码块执行");
    }

    static {
        classRoom = "B1111";
        System.out.println("静态代码块执行");
    }

    public Student() {
        System.out.println("不带参数的构造方法执行");
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("带参数的构造方法执行");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public void testFunc() {
        System.out.println("testFunc方法执行");
    }

    public static void testStatic() {
        System.out.println("testStatic方法执行");
        //静态不依赖对象，不可以使用依赖对象的代码。
//        System.out.println("name:" + this.getName());

        //非要用，先创造对象
//        Student student1 = new Student("张三",10);
//        student1.testFunc();
    }
}
